#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include "bmock_util.hpp"
#include "detail/bmock_raw_mem.hpp"
#include "detail/bmock_test_control_tools.hpp"

namespace bmock {
	static const int           out_buf[]  = {8,9,10,11,12,13,14,15,16};
	static const size_t        L1         = sizeof(out_buf)/sizeof(int);
	static const unsigned char expected[] = {
		0x00,0x00,0x00,0x00  //this length
		,0x24,0x00,0x00,0x00  //next length
		,0x10,0x00,0x00,0x00  //pad length
		,0x0D,0x00,0x00,0x00  //T_len
		,0x08,0x00,0x00,0x00
		,0x09,0x00,0x00,0x00
		,0x0A,0x00,0x00,0x00
		,0x0B,0x00,0x00,0x00
		,0x0C,0x00,0x00,0x00
		,0x0D,0x00,0x00,0x00
		,0x0E,0x00,0x00,0x00
		,0x0F,0x00,0x00,0x00
		,0x10,0x00,0x00,0x00};
		static const size_t        L2         = sizeof(expected);

		static void test_memory(int *buf) {
			const control_tools_ptr t(new test_control_tools());
			raw_mem_checker         chk(t);
			const char              name[] =     "buf";
			chk.set_location(location(__FILE__,__LINE__+1));
			const in_out_rm_pair    m1(buf,name,chk);

			BOOST_CHECK_EQUAL(L2,mismatch_at(expected,expected+L2,(const unsigned char *)buf));
			BOOST_CHECK_EQUAL(L1,mismatch_at(out_buf,out_buf+L1,(const int *)m1.second.begin()));
			BOOST_CHECK_EQUAL(size_t(0),m1.first.get_length());
		}

		BOOST_AUTO_TEST_CASE(test_out_buf_memory_management) {
			BOOST_CHECK_NO_THROW(test_memory(out_raw_mem(out_buf,L1)));
		}
}